<?php
require_once('common.inc.php');
require_once(_INC_PATH.'database.php');
require_once(_INC_PATH.'page.inc.php');

$cmd = @$_REQUEST['cmd'];
if($cmd == "ajaxSetTop"){
	ajaxSetTop();
}else{
	showMyPageList();
}

function showMyPageList()
{
	global $smarty;
	$db = new database();
	$user_id = _getcookie('id');
	$sql_count = "select count(*) from tbl_estimate where user_id='$user_id' and del_flg='0'";
	$total = $db->loadResult($sql_count);
	$curPage = @intval($arr_data['p']);
	if($curPage < 1) $curPage = 1;
	$showNum = _FORVIEWNUM;
	$pageLink = "/myestimate.php";
	$page = new PageClass($total,$curPage,$showNum,$pageLink);
	$limitStart = $page->limitStart;
	$smarty->assign("pageList",$page->pageList);
	
	$sql = "select te.id as est_id,te.content as content,te.create_time as estTime,te.cor_id as cor_id,tc.name as corName from tbl_estimate te left join tbl_corporation tc on tc.id = te.cor_id where user_id='$user_id' and te.del_flg='0' order by te.update_time desc limit $limitStart,$showNum";
	$db->setQuery($sql);
	$data = $db->loadAssocList();
	if(!empty($data))
	{
		foreach($data as $key=>$value){
			$data[$key]['content'] = content_replace($value['content'],'','','img');
			$data[$key]['bgcolor'] = $key%2==0?"est_2":"est_1";
		}
	}
	$smarty->assign("rows",$data);
	Display('addestimate.tpl');
}

?>